from pydantic import BaseModel, Field
from datetime import datetime
from decimal import Decimal
from typing import List, Optional


class ElectricPriceValueCreate(BaseModel):
    time_point: datetime = Field(..., description="时间点")
    price_amount: Decimal = Field(..., description="电价数值")

class ElectricPriceInfoCreate(BaseModel):
    period_unit: str = Field(..., description="划分周期单位")
    period: int = Field(..., description="划分周期")
    price_type: int = Field(..., description="电价类型")
    granularity: int = Field(..., description="划分粒度")
    price_name: str = Field(..., description="电价名称")
    icon: Optional[str] = Field(default="", description="图标")
    background: Optional[str] = Field(default="", description="背景")
    values: List[ElectricPriceValueCreate] = Field(..., description="一组电价数值")

class ElectricPriceInfoCreateList(BaseModel):
    period_unit: str = Field(..., description="划分周期单位")
    period: int = Field(..., description="划分周期")
    price_type: int = Field(..., description="电价类型")
    granularity: int = Field(..., description="划分粒度")
    price_name: str = Field(..., description="电价名称")
    icon: Optional[str] = Field(default="", description="图标")
    background: Optional[str] = Field(default="", description="背景")
    values: List[float] = Field(..., description="一组电价数值")



class ElectricPriceInfoOut(BaseModel):
    price_id: int
    period_unit: str
    period: int
    price_type: int
    granularity: int
    price_name: str
    icon: Optional[str] = None  # 允许为空
    background: Optional[str] = None  # 允许为空

    model_config = {
        "from_attributes": True
    }

class ElectricPriceValueOut(BaseModel):
    price_value_id: int
    price_id: int
    time_point: datetime
    price_amount: Decimal
    icon: Optional[str] = None  # 允许为空
    background: Optional[str] = None  # 允许为空

    class Config:
        from_attributes = True


class PriceChartOut(BaseModel):
    time_list: List[datetime]
    value_list: List[float]

class ElectricPriceInfoDetailOut(BaseModel):
    price_id: int
    period_unit: str
    period: int
    price_type: int
    granularity: int
    price_name: str
    value_list: List[float]
    icon: Optional[str] = None  # 允许为空
    background: Optional[str] = None  # 允许为空

    class Config:
        from_attributes = True